var $ = require('../../utils/Ajax.js');
function Tab(that){
  $.Ajax("api/x_coll", "GET", {}, function (res) {
    console.log(res)
    that.setData({
      MyCollectiom: res.d.collection_e,
      MyCollectiom1: res.d.collection_a
    })
  });
}

Page({
  data: {
    tabs: ["体验", "活动"],
    activeIndex: 0,
    MyCollectiom: null,
    MyCollectiom1: null,
    // 图片地址
    PictureUrl: getApp().PictureUrl
  },
  onLoad: function (){
    var that = this;
    wx.setNavigationBarTitle({
      title: "我的收藏"
    })
  },
  onShow: function () {
    Tab(this);
  },
  // 点击顶部tab栏
  tabClick: function (e) {
    Tab(this);
    this.setData({
      activeIndex: e.currentTarget.id
    });
  },

  // 点击取消收藏
  Collection: function(e){
    var that = this;
    var Type = e.currentTarget.dataset.type;
    var Id = e.currentTarget.dataset.id;
    $.Ajax("api/x_add_coll", "POST", {
      id: Id,
      t: Type
    }, function (ress) {
      if (ress.s){
        wx.showToast({
            title: ress.m,
            icon: 'success',
            duration: 1500
          })
        $.Ajax("api/x_coll", "GET", {}, function (res) {
          that.setData({
            MyCollectiom: res.d.collection_e,
            MyCollectiom1: res.d.collection_a
          })
          wx.showToast({
            title: ress.m,
            icon: 'success',
            duration: 1500
          })
        });
      }else{
        wx.showToast({
          title: res.m,
          icon: 'none',
          image: '../../images/err.png',
          duration: 2000
        })
      }
    });
  },

  // 点击收藏跳转
  GoCollection: function (e) {
    console.log(e)
    var Type = e.currentTarget.dataset.type;
    var Id = e.currentTarget.dataset.id;
    if (Type == 1){
      wx.navigateTo({
        url: '../ExperDetails/ExperDetails?Id=' + Id,
      })
    }else{
      wx.navigateTo({
        url: '../ActiviDetails/ActiviDetails?Id=' + Id,
      })
    }
  }
});